package testIntergration;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import FamilyTherapy.GCWindow;
import FamilyTherapy.Game;
import FamilyTherapy.MagicToolCard;
import FamilyTherapy.Player;

public class testGame_drawEvent {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testDrawEvent_1() throws Exception {
		// preparation

		class GCWindowStub extends GCWindow{
			@Override
			public int requestUsingMT(int currentPlayerNo, Player p[])
			{
			// a simple implementation,
			// which is specially designed for our test case: (5, 1, 1)
			return -1;
			}
		}
		
		GCWindow gcWindow = new GCWindowStub();
		
		Game g = Game.class.newInstance();
		Player[] p = { new Player("a", 1), new Player("b",2)};
		g.setNoOfPlayer(2); 
		
		
		int currentPlayerNo = 0;
		//int decisionMakerNo=0;
		//boolean shareTrigger= false ; 
		//boolean expected = true;

		Method drawEventMethod = g.getClass().getDeclaredMethod("drawEvent",
		GCWindow.class ,int.class, Player[].class);

		drawEventMethod.setAccessible(true);
		
		
		//for input
		String data = "1"; 	//data to be input 
		InputStream stdin = System.in; 
		try {  
			
			System.setIn(new ByteArrayInputStream(data.getBytes()));
			drawEventMethod.invoke(g,gcWindow, currentPlayerNo, p); 
			
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		drawEventMethod.setAccessible(false);

	
		//String expected = "Player a, do you share your SE point to other players?"
				//+ newLine;
		
		//assertEquals(expected, outContent.toString());
		assertEquals(p[currentPlayerNo].getHoldingCard().size(),0);
	}
	@Test
	public void testDrawEvent_2() throws Exception {
		// preparation

		class GCWindowStub extends GCWindow{
			@Override
			public int requestUsingMT(int currentPlayerNo, Player p[])
			{
			// a simple implementation,
			// which is specially designed for our test case: (5, 1, 1)
			return -1;
			}
		}
		
		GCWindow gcWindow = new GCWindowStub();
		
		Game g = Game.class.newInstance();
		Player[] p = { new Player("a", 1), new Player("b",2)};
		g.setNoOfPlayer(2); 
		
		
		int currentPlayerNo = 0;
		//int decisionMakerNo=0;
		//boolean shareTrigger= false ; 
		//boolean expected = true;

		Method drawEventMethod = g.getClass().getDeclaredMethod("drawEvent",
		GCWindow.class ,int.class, Player[].class);

		drawEventMethod.setAccessible(true);
		
		
		//for input
		String data = "a 1"; 	//data to be input 
		InputStream stdin = System.in; 
		try {  
			
			System.setIn(new ByteArrayInputStream(data.getBytes()));
			drawEventMethod.invoke(g,gcWindow, currentPlayerNo, p); 
			
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		drawEventMethod.setAccessible(false);

	
		//String expected = "Player a, do you share your SE point to other players?"
				//+ newLine;
		
		//assertEquals(expected, outContent.toString());
		assertEquals(p[currentPlayerNo].getHoldingCard().size(),0);
	}
	@Test
	public void testDrawEvent_3() throws Exception {
		// preparation

		class GCWindowStub extends GCWindow{
			@Override
			public int requestUsingMT(int currentPlayerNo, Player p[])
			{
			// a simple implementation,
			// which is specially designed for our test case: (5, 1, 1)
			return 3;
			}
		}
		
		GCWindow gcWindow = new GCWindowStub();
		
		Game g = Game.class.newInstance();
		Player[] p = { new Player("a", 1), new Player("b",2)};
		g.setNoOfPlayer(2); 
		p[0].addHoldingCard(4);
		p[0].addHoldingCard(2);
		p[0].addHoldingCard(3);
		p[0].addHoldingCard(1);
		
		
		
		int currentPlayerNo = 0;
		//int decisionMakerNo=0;
		//boolean shareTrigger= false ; 
		//boolean expected = true;

		Method drawEventMethod = g.getClass().getDeclaredMethod("drawEvent",
		GCWindow.class ,int.class, Player[].class);

		drawEventMethod.setAccessible(true);
		
		
		//for input
		String data = "a * 100 1"; 	//data to be input 
		InputStream stdin = System.in; 
		try {  
			
			System.setIn(new ByteArrayInputStream(data.getBytes()));
			drawEventMethod.invoke(g,gcWindow, currentPlayerNo, p); 
			
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		drawEventMethod.setAccessible(false);
		System.out.println(p[0].getHoldingCard());
	
		//String expected = "Player a, do you share your SE point to other players?"
				//+ newLine;
		
		//assertEquals(expected, outContent.toString());
		assertEquals(p[currentPlayerNo].getHoldingCard().size(),3);
	}
	@Test
	public void testDrawEvent_4() throws Exception {
		// preparation

		class GCWindowStub extends GCWindow{
			@Override
			public int requestUsingMT(int currentPlayerNo, Player p[])
			{
			// a simple implementation,
			// which is specially designed for our test case: (5, 1, 1)
			return 1;
			}
		}
		
		GCWindow gcWindow = new GCWindowStub();
		
		Game g = Game.class.newInstance();
		Player[] p = { new Player("a", 1), new Player("b",2)};
		g.setNoOfPlayer(2); 
		
		
		int currentPlayerNo = 0;
		//int decisionMakerNo=0;
		//boolean shareTrigger= false ; 
		//boolean expected = true;

		Method drawEventMethod = g.getClass().getDeclaredMethod("drawEvent",
		GCWindow.class ,int.class, Player[].class);

		drawEventMethod.setAccessible(true);
		
		
		//for input
		String data = "a 1"; 	//data to be input 
		InputStream stdin = System.in; 
		try {  
			
			System.setIn(new ByteArrayInputStream(data.getBytes()));
			drawEventMethod.invoke(g,gcWindow, currentPlayerNo, p); 
			
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		drawEventMethod.setAccessible(false);

	
		//String expected = "Player a, do you share your SE point to other players?"
				//+ newLine;
		
		//assertEquals(expected, outContent.toString());
		assertEquals(p[currentPlayerNo].getHoldingCard().size(),0);
	}
}
